﻿using EasyAdmin.Domain.Entities.Systems;
using EasyAdmin.Domain.Shared.Enums;
using EasyCore.DataValidation.Validators;
using EasyCore.ObjectMapper;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyAdmin.Application.Contracts.Systems.Menus.Dtos
{
    [MapTo(typeof(SysMenu))]
    [MapFrom(typeof(SysMenu))]
    public class CreateUpdateMenuInput
    {
        /// <summary>
        /// 菜单唯一标识
        /// </summary>
        public long? Id { get; set; }

        /// <summary>
        /// 父菜单唯一标识
        /// </summary>
        public long ParentId { get; set; }

        /// <summary>
        /// 菜单名称
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 路由路径：主要用于VUE单页面应用【用于访问页面】
        ///</summary>
        public string RoutePath { get; set; }

        /// <summary>
        /// 组件路径：页面的实际路径
        /// </summary>
        public string ComponentPath { get; set; }

        /// <summary>
        /// 菜单类项：目录、页面
        /// </summary>
        public MenuType MenuType { get; set; }

        /// <summary>
        /// 菜单图标
        /// </summary>
        public string Icon { get; set; }

        /// <summary>
        /// 菜单是否显示
        /// </summary>
        public bool IsShow { get; set; }

        /// <summary>
        /// 是否是首页
        /// </summary>
        public bool IsHome { get; set; }

        /// <summary>
        /// 是否禁用
        /// </summary>
        public bool IsDisabled { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int OrderSort { get; set; }

        /// <summary>
        /// 当前页面的操作按钮列表
        /// </summary>
        public List<long> Operations { get; set; }
    }

    public class MenuValidator : EasyValidator<CreateUpdateMenuInput>
    {
        public MenuValidator()
        {
            RuleFor(x => x.Title).MaximumLength(30).WithMessage("菜单名称最大长度不能超过30个字符");
            RuleFor(x => x.RoutePath).NotEmpty().When(m => m.MenuType == MenuType.Menu).WithMessage("路由路径不能为空")
                .MaximumLength(150).WithMessage("路由路径最大长度不能超过150个字符");
            RuleFor(x => x.ComponentPath).NotEmpty().When(m => m.MenuType == MenuType.Menu).WithMessage("组件路径不能为空")
    .MaximumLength(150).WithMessage("组件路径最大长度不能超过150个字符");
            RuleFor(x => x.Icon).MaximumLength(30).WithMessage("菜单图标最大长度不能超过30个字符");
            RuleFor(x => x.OrderSort).GreaterThanOrEqualTo(0).WithMessage("排序不能少于0");
        }


    }


}
